﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace LightSwitchApplication
{
    public class RestrictionRegulationsController : BasicController
    {
        // GET api/<controller>
        public object Get() //IEnumerable<string>
        {
            var result = (from r in DataWorkspace.MMC_Content.RestrictionRegulations.GetQuery().Execute()
                select new { Id = r.Id
                    , From = ( r.DateFrom == null ? null : r.DateFrom.Value.ToString("hh:nn") )
                    , To = (r.DateTo == null ? null : r.DateTo.Value.ToString("hh:nn"))
                    , Description = r.Restriction.Description , Hours = r.Hours, Minutes = r.Minutes , Price = r.Price, WeekBitMask = r.WeekBitMask
                });
            return result;
        }

        // GET api/<controller>/5
        public object Get(int id)
        {
            return (from r in DataWorkspace.MMC_Content.RestrictionRegulations.GetQuery().Execute()
                    where r.Id == id
            select new
            { Id = r.Id
                , From = ( r.DateFrom == null ? null : r.DateFrom.Value.ToString("hh:nn") )
                , To = (r.DateTo == null ? null : r.DateTo.Value.ToString("hh:nn"))
                , Description = r.Restriction.Description, Hours = r.Hours, Minutes = r.Minutes, Price = r.Price, WeekBitMask = r.WeekBitMask
            }).FirstOrDefault();
        }


        //public object Get(int PlaceId) //IEnumerable<string>
        //{
        //    var result = (from r in DataWorkspace.MMC_Content.Restrictions.GetQuery().Execute() where r.Place.Id == PlaceId
        //        select new { Id = r.Id
        //            , PlaceId = (r.Place == null ? 0 : r.Place.Id)
        //            , From = ( r.DateFrom == null ? null : r.DateFrom.Value.ToString("hh:nn") )
        //            , To = (r.DateTo == null ? null : r.DateTo.Value.ToString("hh:nn"))
        //            , Description = r.Description , Hours = r.Hours, Minutes = r.Minutes , Price = r.Price, WeekBitMask = r.WeekBitMask
        //        });
        //    return result;
        //}

        public object Get(short? MaxHours, decimal? MaxPrice, DateTime? RestrictionDate, int? PlaceId) //IEnumerable<string>
        {
            var result = (from r in DataWorkspace.MMC_Content.RestrictionRegulationsFiltered(MaxHours, MaxPrice, RestrictionDate).Execute()
                          //where r.Place.Id == PlaceId
                select new { Id = r.Id
                    , From = ( r.DateFrom == null ? null : r.DateFrom.Value.ToString("hh:nn") )
                    , To = (r.DateTo == null ? null : r.DateTo.Value.ToString("hh:nn"))
                    , Description = r.Restriction.Description , Hours = r.Hours, Minutes = r.Minutes , Price = r.Price , WeekBitMask = r.WeekBitMask
                });
            return result;
        }

        //// POST api/<controller>
        //public void Post([FromBody]string value)
        //{
        //}

        //// PUT api/<controller>/5
        //public void Put(int id, [FromBody]string value)
        //{
        //}

        //// DELETE api/<controller>/5
        //public void Delete(int id)
        //{
        //    var place = DataWorkspace.MMC_Content.Restrictions_SingleOrDefault(id);
        //    if (place != null)
        //    {
        //        place.Delete();
        //        DataWorkspace.MMC_Content.SaveChanges();
        //    }
        //}
    }
}